#include "person.h"

Person::Person()
: m_id( INVALID_ID ),
  m_name( INVALID_STR ),
  m_borrowedBooksList( 0 )
{
	// Default constructor
}

Person::Person( const ID &id,
                const QString &name,
                const QVector<ID> &booksList)
: m_id( id ),
  m_name( name ),
  m_borrowedBooksList( booksList ),
  m_everBorrowed( false )
{
}

void Person::setId( const ID &id )
{
	m_id = id;
}

void Person::setName( const QString &name )
{
	m_name = name;
}

void Person::setBorrowdBooksList( const QVector<ID> &booksList )
{
	m_borrowedBooksList = booksList;
}

void Person::borrowBook( const ID &bookId )
{
	m_everBorrowed = true;
	m_borrowedBooksList.append( bookId );
}

void Person::returnBook(const ID &bookId)
{
	for( int i = 0; i < m_borrowedBooksList.size(); i++ )
	{
		if( m_borrowedBooksList.value( i ) == bookId )
		{
			m_borrowedBooksList.remove( i );
			break;
		}
	}
}

ID Person::getId() const
{
	return m_id;
}

QString Person::getName() const
{
	return m_name;
}

QVector<ID> Person::getBorrowdBooksList() const
{
	return m_borrowedBooksList;
}

bool Person::hasEverBorrowed() const
{
	return m_everBorrowed;
}
